$(function(){
	var url = common.url();
	var began = 0;
	var listlen1 = 15;
	var listlen2 = 14;
	var listlen3 = 12;
	
	//关于点击后的连接问题，以及内容
	var arr = common.search();
	
	var newsarr = common.baseval('project');
	var showlist = 'gcgk';
	var arrid = 1;
	var showfirst = 1;
	if(arr.valchild){
		showfirst = arr.valchild;
	}
	if(arr.valid){
		showlist = arr.valid;
	}
	if(arr.proj && arr.proj <= newsarr.length){
		arrid = arr.proj;
	};
	
	
	
	if(arr.valid == 'gcgk'){
		$('.contll-nav li ol').css({'display':'block'})
		$('.contll-nav li ol li').eq(showfirst-1).children('a').css({'color':'#b99663'});
		var vhtml = '<li><a href="">工程概况</a>&nbsp;>&nbsp;</li>';
		$('.header-list li:last').before(vhtml);
		$('.header-list li:last a').html(newsarr[0].child[arr.valchild-1]);
		var jk = common.Interface('proj1')[arr.valchild-1];
		fnhash()
		common.hash('page',fnhash1);
	}else if(arr.valid == 'zbfb'){
		$('.header-list li:last a').html(newsarr[arrid-1].title);
		var jk = common.Interface('proj2')[0];
		common.hash('page',fnhash2);
	}else if(arr.valid == 'wcxm'){
		$('.header-list li:last a').html(newsarr[arrid-1].title);
		var jk = common.Interface('proj4')[0];
		common.hash('page',fnhash3);
	}
	$('.proj-box .'+ showlist).css({'display':'block'});
	
	$('.contll-nav .con-li').eq(arrid-1).addClass('hov6').siblings().removeClass('hov6');
	// 工程概况置顶
	function fnhash(hash){
		//分页
		if(common.hashlist().page){
			began = (common.hashlist().page-1)*listlen1
		}
		if(arr.valchild == 1){
			var url = jk +'?offset='+ began +'&limit='+ listlen1
		}else{
			var url = jk +'&offset='+ began +'&limit='+ listlen1
		}
		
		$.ajax({
				url : url,
				type: "POST",
				error: function(request) {
					console.log(request)
				},
				dataType:"json",
				success: function(data) {
					if(!data.ret) return;
					var json = data.data;
					var data = data.data.rows;
					if(data.length>0){
						var html = '';
						for(var i=0;i<data.length;i++){
							if(i<5){
								html += '<li class=""><div class="sch-box">\
				 				<img src="'+ data[i].picture +'" alt="" />\
				 				<div class="reimgbg"></div>\
								<a href="/school.htm?schid='+ data[i].id +'&valchild='+arr.valchild +'" class="reimg-link">查看项目</a>\
				 			</div><p class="sch-name"><span>'+ data[i].name +'</span></p></li>';
							}
						}
						$('.school-list').html(html);
					}
					
				}
			})
	}
	function fnhash1(hash){
		//分页
		if(common.hashlist().page){
			began = (common.hashlist().page-1)*listlen1+5;
		}
		if(began == 0){
			began =5;
		}
		if(arr.valchild == 1){
			var url = jk +'?offset='+ began +'&limit='+ listlen1;
		}else{
			var url = jk +'&offset='+ began +'&limit='+ listlen1;
		}
		
		$.ajax({
				url : url,
				type: "POST",
				error: function(request) {
					console.log(request)
				},
				dataType:"json",
				success: function(data) {
					if(!data.ret) return;
					var json = data.data;
					var data = data.data.rows;
					var pages =Math.ceil(json.total / listlen1);
					common.pagesgn(pages,6);
					if(data.length>0){
						var html = '';
						for(var i=0;i<data.length;i++){
							html +='<li><a href="/school.htm?schid='+ data[i].id +'&valchild='+ arr.valchild +'">'+ data[i].name +'</a></li>';	
						}
						$('.zhiding').html(html);
					}else{
						$('.pages').css({'display':'none'})
					}
					
				}
			})
	}
	function fnhash2(hash){
		//分页
		if(common.hashlist().page){
			began = (common.hashlist().page-1)*listlen2;
		}
		var url = jk +'?offset='+ began +'&limit='+ listlen2;
		$.ajax({
				url : url,
				type: "POST",
				error: function(request) {
					console.log(request)
				},
				dataType:"json",
				success: function(data) {
					if(!data.ret) return;
					var json = data.data;
					var data = data.data.rows;
					var pages =Math.ceil(json.total / listlen2);
					common.pagesgn(pages,6);
					if(data.length>0){
						var html = '';
						for(var i=0;i<data.length;i++){
							var title = common.maxlen(data[i].title,30,true);
							var times = common.timechange(data[i].pubdate,true);
							html +='<li class="clear">\
								<a href="/detail.htm?id='+ data[i].id +'" class="fl">'+ title +'</a>\
								<div class="zb-seetime fr"><p class="zb-time fl">'+ times +'</p>\
									<p class="zb-see fl">'+ data[i].readCount +'</p>\
								</div></li>'
						}
						$('.zbfb-box').html(html)
					}else{
						$('.pages').css({'display':'none'})
					}
					
				}
			})
	}
	function fnhash3(hash){
		//分页
		if(common.hashlist().page){
			began = (common.hashlist().page-1)*listlen3;
		}
		var url = jk +'?offset='+ began +'&limit='+ listlen3;
		$.ajax({
				url : url,
				type: "POST",
				error: function(request) {
					console.log(request)
				},
				dataType:"json",
				success: function(data) {
					if(!data.ret) return;
					var json = data.data;
					var data = data.data.rows;
					var pages =Math.ceil(json.total / listlen3);
					common.pagesgn(pages,6);
					if(data.length>0){
						var html = '';
						for(var i=0;i<data.length;i++){
							html +='<li><div class="wcimg-box">\
							<a href="/schoollist.htm?schxmid='+ data[i].id +'">\
								<img src="'+ data[i].schoolPicture +'" alt="" />\
								<div class="img-mbbg"></div>\
								<p class="wcxm-chakan">点击查看</p></a>\
						</div><p class="wc-sch">'+ data[i].schoolName +'</p>\
						<div class="wcval-box">\
							<p class="wc-title">'+ data[i].title +'</p>\
							<a href="schoollist.htm?schxmid='+ data[i].id +'" class="wc-link">了解详情</a>\
							<p class="wc-see">'+ data[i].readCount +'</p></div></li>'
						}
						$('.wcxm-box').html(html)
					}else{
						$('.wcxm-box').css({'display':'none'});
					}
					
				}
			})
	}
	
})